const fs = require('fs');

function p1() {
    return new Promise((resolve, reject) => {
        fs.readFile('1.txt', 'utf8', (err, result) => {
            if (err != null) {
                reject(err);
            } else {
                resolve(result);
            }
        });
    });
}

function p2() {
    return new Promise((resolve, reject) => {
        fs.readFile('2.txt', 'utf8', (err, result) => {
            if (err != null) {
                reject(err);
            } else {
                resolve(result);
            }
        });
    });
}

function p3() {
    return new Promise((resolve, reject) => {
        fs.readFile('3.txt', 'utf8', (err, result) => {
            if (err != null) {
                reject(err);
            } else {
                resolve(result);
            }
        });
    });
}

p1().then((result) => {
    console.log(result);
    return p2();
})
    .then((result) => {
        console.log(result);
        return p3();
    })
    .then((result) => {
        console.log(result);
    })